/**
 * 参数设置管理初始化
 */
var Hotel = {
    id: "hotelTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Hotel.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '离店时间', field: 'check_out_time', visible: false, align: 'center', valign: 'middle'},
        {title: '创建时间', field: 'add_time', visible: false, align: 'center', valign: 'middle'},
        {title: '联系手机', field: 'phone', visible: false, align: 'center', valign: 'middle'},
        {title: '订单号/创建时间', field: 'order_number', visible: true, align: 'center', valign: 'middle',formatter: function (value, row, index) {
            return value+"<br/><br/>"+row.add_time;
           }
        
        },
        {title: '异地订单号', field: 'api_order_number', visible: true, align: 'center', valign: 'middle'},
        {title: '酒店名称', field: 'hotel_name', visible: true, align: 'center', valign: 'middle'},
        {title: '入住/离店时间', field: 'check_in_time', visible: true, align: 'center', valign: 'middle',formatter: function (value, row, index) {
                return value+"<br/><br/>"+row.check_out_time;
            }	
        },
        {title: '房间数', field: 'book_number', visible: true, align: 'center', valign: 'middle'},
        {title: '支付总价', field: 'pay_price', visible: true, align: 'center', valign: 'middle'},
        {title: '订单状态', field: 'status', visible: true, align: 'center', valign: 'middle',formatter: function (value, row, index) {
            if(value=='50')
            {
                return "待支付";
            }else if(value=='60')
            {
            	 return "待确认";
            }else if(value=='70')
            {
           	 return "已确认";
            }else if(value=='80')
            {
              	 return "退订中";
            }else if(value=='508')
            {
             	 return "已退订";
            }else if(value=='90')
            {
           	 return "已取消";
            }
        }},
        {title: '联系人/联系手机', field: 'name', visible: true, align: 'center', valign: 'middle',formatter: function (value, row, index) {
                return value+"<br/><br/>"+row.phone;
            }		
        
        }
    ];
};



/**
 * 导出
 */
Hotel.excel = function () {
	var url = "/hotelOrder/exPort?";
	if($("#start_time").val()=="")
	{
		  Feng.error("请选择开始时间！");
          return false;
	}
	url = url+"&start_time="+$("#start_time").val().replace("/","-");
	if($("#end_time").val() == "") {
	        Feng.error("请选择结束时间！");
	        return false;
	        }else{
	        	 url = url+"&end_time="+$("#end_time").val().replace("/","-");
	        }
	 window.location.href=url;
};




/**
 * 查询参数设置列表
 */
Hotel.search = function () {
    var queryData = {};
    queryData['order_number'] = $("#order_number").val();
    queryData['api_order_number'] = $("#api_order_number").val();
    queryData['phone'] = $("#phone").val();
    queryData['status'] = $("#status").val();
    queryData['start_time'] = $("#start_time").val().replace("/","-");
    if($("#start_time").val() != "") {
        if($("#end_time").val() == "") {
            Feng.error("请选择结束时间！");
            return false;
        }else{
            queryData['end_time'] = $("#end_time").val().replace("/","-");
        }
    }
    Hotel.table.refresh({query: queryData});
};

$(function () {
    $("#start_time").attr('type','date');
    $("#end_time").attr('type','date');
    var defaultColunms = Hotel.initColumn();
    var table = new BSTable(Hotel.id, "/hotelOrder/list", defaultColunms);
    table.setPaginationType("server");
    Hotel.table = table.init();
});
